#!/bin/sh 

HOSTNAME=$1

no_change() {
  kdialog --title "EeePC Config" --sorry "No changes made."
}

change() {
  NEW=$1
  EXISTING=`cat /etc/hostname`

  if [ "$NEW" = "$EXISTING" ]; then
    no_change
  else
    sudo sh -c "echo $NEW > /etc/hostname"
    kdialog --title "EeePC Config" --msgbox "Hostname Saved.\n\nYou may need to restart for some applications to recognise this change.  Most things should be ok though."
  fi
}

if [ -z "$HOSTNAME" ]; then
  HOSTNAME=`cat /etc/hostname`
  RESULT=`kdialog --title "Configuration" --inputbox "Change hostaname" "$HOSTNAME"`
  if [ $? -eq "0" ]; then
    change $RESULT
  else
    no_change
  fi
else 
  change $RESULT
fi
